package com.lsh.oms.core.service.business.impl;

import com.lsh.base.common.model.CommonResult;
import com.lsh.oms.core.model.order.OrderHead;
import com.lsh.oms.core.proxy.service.OfcProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by panxudong on 17/3/23.
 */
@Service("cancelOrderMisServiceImpl")
public class CancelOrderMisServiceImpl extends AbstractCancelOrderMisService {

    @Autowired
    private OfcProxy ofcProxy;

    @Override
    protected CommonResult<Boolean> execute(OrderHead orderHead, String logSign) {
        Long orderCode = orderHead.getOrderCode();
        int status = orderHead.getOrderStatus().intValue();

        if (super.isFulfill(status)) {
            CommonResult<Boolean> result = ofcProxy.cancelOrder(orderCode, logSign);
            return result;
        }

        return CommonResult.success(true);
    }

    @Override
    protected boolean isForceCancel(OrderHead orderHead, String logSign) {
        CommonResult<Boolean> result = ofcProxy.isForceCancel(orderHead.getOrderCode(), logSign);
        return result.getData().booleanValue();
    }
}
